﻿/// <reference path="../../../Sustainalytics.Core.UI/modules/Routing/adapters/RoutingEngineAdapter.ts" />
module Sustainalytics.Shell {

    import Common = Sustainalytics.Common;
    import Routing = Sustainalytics.Routing;

    var mod = angular.module(shellModuleName);


    // configure module
    mod.config([Sustainalytics.Routing.routingServiceName + 'Provider', '$httpProvider', (routingProvider: Routing.IRoutingStateServiceProvider, $httpProvider, $urlRouterProvider) => {

        $httpProvider.interceptors.push(Sustainalytics.Authentication.authenticationHttpInterceptorName);

        //$urlRouterProvider.when('/research/:companyName', '/research/overview/:companyName');

        routingProvider
            .state('home',
            {
                url: '/home', templateUrl: '/views/Home.html', controller: 'HomeController'
            },
            new Routing.RouteSecurity(),
            ['modules/Home/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('account',
                {
                    url: '/account', templateUrl: '/views/Account.html', controller: 'AccountController'
                },
            new Routing.RouteSecurity(),
            ['modules/Account/module.json'])

            .state('policies',
            {
                url: '/policies', templateUrl: '/views/Policies.html', controller: ''
            },
            null,
            ['modules/Home/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('faq',
            {
                url: '/faq', templateUrl: '/views/FAQ.html', controller: ''
            },
            null,
            ['modules/Home/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('events',
            {
                url: '/events', templateUrl: '/views/Event/EventList.html', controller: 'EventListController'
            },
            new Routing.RouteSecurity(),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Events/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])
            
            .state('eventDetails',
            {
                url: '/events/:eventId', templateUrl: '/views/Event/EventView.html', controller: 'EventViewController'
            },
            new Routing.RouteSecurity(),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Events/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('mostactivereports',
            {
                url: '/mostactivereports', templateUrl: '/views/MostActiveReports/List.html', controller: 'MostActiveReportController', controllerAs: 'mar'
            },
            new Routing.RouteSecurity(),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/MostActiveReports/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('mostrecentactivity',
            {
                url: '/mostrecentactivity', templateUrl: '/views/MostRecentActivity/List.html', controller: 'MostRecentActivityController', controllerAs: 'mra'
            },
            new Routing.RouteSecurity(),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/MostRecentActivity/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('news',
            {
                url: '/news', templateUrl: '/views/News/NewsList.html', controller: 'NewsListController'
            },
            new Routing.RouteSecurity(),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/News/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('newsDetails',
            {
                url: '/news/:newsId', templateUrl: '/views/News/NewsView.html', controller: 'NewsViewController'
            },
            new Routing.RouteSecurity(),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/News/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('insights',
            {
                url: '/insights', templateUrl: '/views/Insights/InsightsList.html', controller: 'InsightsListController'
            },
            new Routing.RouteSecurity(),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Insights/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('insightDetails',
            {
                url: '/insights/:id', templateUrl: '/views/Insights/InsightsView.html', controller: 'InsightsViewController'
            },
            new Routing.RouteSecurity(),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Insights/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('portfolios',
            {
                url: '/portfolios', templateUrl: '/views/Portfolio/Portfolios.html', controller: 'PortfolioListController'
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/portfolios', parameters: [{ key: 'shortName', value: 'portfoliomanagement' }] }),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Portfolio/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            //new tab
            .state('portfolioAnalytics',
            {
                url: '/portfolios/analytics', templateUrl: '/views/Portfolio/PortfoliosAnalytics.html', controller: 'PortfolioAnalyticsController'
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/portfolios', parameters: [{ key: 'shortName', value: 'portfolioanalytics' }] }),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Portfolio/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])
            //end new tab

            .state('subscribeToPortfolio',
            {
                url: '/portfolios/monitoring', templateUrl: '/views/Portfolio/SubscribeToPortfolio.html', controller: 'SubscribeToPortfolioController'
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/subscribetoportfolio', parameters: []  }),
            ["modules/Common/module.json", "modules/LRTM/module.json", "modules/SearchBoxModule/module.json", "modules/Pager/module.json", "modules/Routing/module.json", 'modules/Portfolio/module.json'])

            .state('portfolioDetails',
            {
                url: '/portfolios/:id', templateUrl: '/views/Portfolio/PortfolioOverview.html', controller: 'PortfolioOverviewController'
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/portfolios', parameters: [{ key: 'shortName', value: 'portfoliomanagement' }] }),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Portfolio/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('researchCompanyList',
            {
                url: '/research/company', templateUrl: '/views/Research/Company/CompanyList.html', controller: 'CompanyListController'
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/companies', parameters: [{ key: 'shortName', value: 'companyoverview' }] }),
            ['modules/CompanySearchModule/module.json', 'modules/Research/module.json', 'modules/LRTM/module.json', 'modules/Portfolio/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('researchOverviewCompany',
            {
                url: '/research/overview/:companyName', templateUrl: '/views/Research/CompanyOverview/Company.html', controller: 'CompanyOverviewController'
            },
            new Routing.RouteSecurity(),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/CompanyOverview/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Research/module.json', 'modules/Company/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('researchGlobalCompactCompany',
            {
                url:'/research/globalcompact/company/:companyName', templateUrl: '/views/Research/GlobalCompact/Company.html', controller: 'GCCompanyController'
            },
            new Routing.RouteSecurity().addService('GCRouteSecurityService'),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Research/module.json', 'modules/GCCS/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('researchGlobalCompactCompanyAssessment',
            {
                url:'/research/globalcompact/company/:companyName/:overallAssessment', templateUrl: '/views/Research/GlobalCompact/Company.html', controller: 'GCCompanyController'
            },
            new Routing.RouteSecurity().addService('GCRouteSecurityService'),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Research/module.json', 'modules/GCCS/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('researchGlobalCompact',
            {
                url:'/research/globalcompact', templateUrl: '/views/Research/GlobalCompact/MultiCompanyReport.html', controller: 'GCMultiCompanyReportController'
            },
            new Routing.RouteSecurity().addService('GCMultiCompanyRouteSecurityService'),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/GCCS/module.json', 'modules/Research/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('researchGlobalCompactOverallAssessment',
            {
                url:'/research/globalcompact/:overallAssessment', templateUrl: '/views/Research/GlobalCompact/MultiCompanyReport.html', controller: 'GCMultiCompanyReportController'
            },
            new Routing.RouteSecurity().addService('GCMultiCompanyRouteSecurityService'),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/GCCS/module.json', 'modules/Research/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('researchPI',
            {
                url:'/research/pi', templateUrl: '/views/Research/ProductInvolvement/CompanyAssessmentList.html', controller: 'CompanyAssessmentListController'
            },
            new Routing.RouteSecurity().addService('PIMultiCompanyRouteSecurityService'),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Research/module.json', 'modules/PI/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('researchPICompany',
            {
                url:'/research/pi/:companyName', templateUrl: '/views/Research/ProductInvolvement/CompanyAssessmentDetails.html', controller: 'CompanyAssessmentDetailsController'
            },
            new Routing.RouteSecurity().addService('PICompanyRouteSecurityService'),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/PI/module.json', 'modules/Research/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('researchGovernanceCompany',
            {
                url:'/research/governance/:companyName', templateUrl: '/views/Research/Governance/Company.html', controller: 'GovernanceProfileController', controllerAs: 'governanceProfile'
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/governance', parameters: [] }),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Governance/module.json', 'modules/Research/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])
            
            .state('researchRiskRatingsList',
            {
                url: '/research/riskratings', templateUrl: '/views/Container.html', params: { module: 'riskRating' }
            },
            new Routing.RouteSecurity(),
            ['modules/Container/module.json', 'modules/Research/module.json', 'modules/Company/module.json']) 

            .state('researchRiskRatingsCompany',
            {
                url: '/research/riskratings/:companyName', templateUrl: '/views/Container.html', params: { module: 'riskRating' }
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/riskratings/{companyId}', parameters: [] }),
            ['modules/Container/module.json', 'modules/Research/module.json', 'modules/Company/module.json', 'modules/LRTM/module.json'])          
            
            .state('researchEsgRatingsCompany',
            {
                url: '/research/esgRatings/:companyName', templateUrl: '/views/Research/EsgRatings/Company.html'
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/esgratings/{companyId}', parameters: [] }),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/EsgRatings/module.json', 'modules/Research/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])          

            .state('researchControversiesCompany',
            {
                url:'/research/controversies/:companyName', templateUrl: '/views/Research/Controversies/Company.html', controller: 'ControversiesController'
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/company/{companyId}/esgControversyIndicator', parameters: [] }),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Controversies/module.json', 'modules/Research/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('researchCompany',
            {
                url:'/research/:companyName'
            })

            .state('toolsScreening',
            {
                url: '/tools/screening', templateUrl: '/views/Tools/ScreeningTool/Filters.html', controller: 'FiltersController', controllerAs: 'fltCtrl'
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/screeningtool', parameters: [] }),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/ScreeningTool/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('toolsReport',
            {
                url: '/tools/report', templateUrl: '/views/Tools/ScreeningTool/Filters.html', controller: 'FiltersController', controllerAs: 'fltCtrl'
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/datareportingtool', parameters: [] }),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/ScreeningTool/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('editFilterDetails',
            {
                url: '/tools/screening/filters/:filterId', templateUrl: '/views/Tools/ScreeningTool/FilterEdit.html', controller: 'EditFilterController'
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/filters/{filterId}', parameters: [] }),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/ScreeningTool/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('editReportDetails',
            {
                url: '/tools/report/filters/:filterId', templateUrl: '/views/Tools/ScreeningTool/FilterEdit.html', controller: 'EditFilterController'
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/filters/{filterId}', parameters: [] }),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/ScreeningTool/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('companyDetails',
            {
                url:'/company/:companyId', templateUrl: '/views/Company.html', controller: 'CompanyController'
            },
            new Routing.RouteSecurity(),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Company/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('lrtmtest',
            {
                url:'/lrtmtest', templateUrl: '/views/LongRunningTaskManagerTest.html', controller: 'LongRunningTaskManagerTestController'
            },
            new Routing.RouteSecurity(),
            ['modules/CompanySearchModule/module.json', 'modules/LRTMTest/module.json'])

            .state('userForgotPassword',
            {
                url: '/forgotPassword', templateUrl: '/views/Login/ForgotPassword.html', controller: Sustainalytics.Security.Login.accountControllerName
            },
            new Routing.RouteSecurity(),
            [])

            .state('passwordChangeConfirmation',
            {
                url: '/passwordChangeConfirmation', templateUrl: '/views/Login/PasswordChangeConfirmation.html', controller: Sustainalytics.Security.Login.accountControllerName
            },
            new Routing.RouteSecurity(),
            [])


            .state('userForgotPasswordConfirmation',
            {
                url: '/forgotPasswordConfirmation', templateUrl: '/views/Login/ForgotPasswordConfirmation.html', controller: Sustainalytics.Security.Login.accountControllerName
            },
            new Routing.RouteSecurity(),
            [])

            .state('userSetPassword',
            {
                url: '/setPassword/:user', templateUrl: '/views/Login/SetPassword.html', controller: Sustainalytics.Security.Login.accountControllerName
            },
            new Routing.RouteSecurity(),
            [])

            .state('userChangePassword',
            {
                url: '/changePassword/:user', templateUrl: '/views/Login/ChangePassword.html', controller: Sustainalytics.Security.Login.accountControllerName
            },
            new Routing.RouteSecurity(),
            [])

            .state('userChangePasswordTempKey',
            {
                url: '/changePassword/:user/:tempKey', templateUrl: '/views/Login/ChangePassword.html', controller: Sustainalytics.Security.Login.accountControllerName
            },
            new Routing.RouteSecurity().setLogout(true, true),
            [])

            .state('userPasswordExpired',
            {
                url:'/passwordExpired', templateUrl: '/views/Login/PasswordExpired.html', controller: Sustainalytics.Security.Login.accountControllerName
            },
            new Routing.RouteSecurity(),
            [])
             
            .state('ipLogin',
            {
                url: '/iplogin', templateUrl: '/views/Login/Login.html', controller: Sustainalytics.Security.Login.accountControllerName
            },
            new Routing.RouteSecurity().setLogout(true, true),
            [])
            .state('userLogin',
            {
                url:'/login', templateUrl: '/views/Login/Login.html', controller: Sustainalytics.Security.Login.accountControllerName
            },
            new Routing.RouteSecurity().setLogout(true, false),
            [])

            .otherwise('home', null);
    }]);

    // add sitemaps on module init
    mod.run(['NavigationService', (NavigationService: Navigation.INavigationService) => {
        // add sitemaps
        SiteMapUtility.addSiteMaps(NavigationService);
    }]);
    
    // bootstraping
    angular.element(document).ready(function () {
        angular.bootstrap.call(angular, document, ['shell'], { strictDi: true });
    });
}